# SuperFastPython.com
# example of issuing a task with apply_async() to the process pool with arguments
from time import sleep
from multiprocessing.pool import Pool
 
# task executed in a worker process
def task(message):
    # report a message
    print(f'Task executing: {message}', flush=True)
    # block for a moment
    sleep(1)
    # report a message
    print(f'Task done: {message}', flush=True)
 
# protect the entry point
if __name__ == '__main__':
    # create and configure the process pool
    pool = Pool()
    for item in range(10):
        # issue tasks to the process pool
        pool.apply_async(task, args=('Hello world',))
    # close the process pool
    pool.close()
    # wait for all tasks to finish
    pool.join()